#include <stdio.h>
#define N 5
int main() {
    int a[N][N] = {0};
    int i = 0, j = N / 2; 
    int k, row, col;
    a[i][j] = 1; 
    for (k = 2; k <= N * N; k++) {
        row = (i - 1 + N) % N; 
        col = (j + 1) % N;   
        if (a[row][col] == 0) {
            i = row;
            j = col;
        } else {
            i = (i + 1) % N;
        }
        a[i][j] = k;
    }
    printf("%d阶魔方阵:\n", N);
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            printf("%4d", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}